package homework;

import java.util.Stack;

//作业标题(1788)
//3.栈的弹出压入序列
//
//作业内容
//栈的弹出压入序列(仅上传代码即可)
//https://www.nowcoder.com/practice/d77d11405cc7470d82554cb392585106?tpId=13&&tqId=11174&rp=1&ru=/activity/oj&qru=/ta/coding-interviews/question-ranking
public class h1788 {
    public class Solution {
        /**
         * 代码中的类名、方法名、参数名已经指定，请勿修改，直接返回方法规定的值即可
         *
         *
         * @param pushV int整型一维数组
         * @param popV int整型一维数组
         * @return bool布尔型
         */
        private Stack<Integer> stack = new Stack<>();
        public boolean IsPopOrder (int[] pushV, int[] popV) {
            // write code here
            for(int i = 0, j = 0; i < pushV.length; i++)
            {
                while(!stack.empty() && popV[j] == stack.peek()){
                    j++;
                    stack.pop();
                }
                stack.push(pushV[i]);
            }

            return stack.empty();
        }
    }
}
